package com.example.sharedelementdemo

import android.content.Context
import android.view.ViewGroup
import android.widget.ImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.QuickViewHolder

class MyAdapter(val callBack: CallBack) : BaseQuickAdapter<LocalBean, QuickViewHolder>() {
    override fun onCreateViewHolder(
        context: Context,
        parent: ViewGroup,
        viewType: Int
    ): QuickViewHolder {
// 返回一个 ViewHolder
        return QuickViewHolder(R.layout.item_layout, parent)
    }

    override fun onBindViewHolder(holder: QuickViewHolder, position: Int, item: LocalBean?) {
// 设置item数据
        holder.setImageResource(R.id.item_image, item!!.mipmap)

        holder.getView<ImageView>(R.id.item_image).setOnClickListener {
            callBack.select(position, it as ImageView)
        }
    }

    interface CallBack {
        fun select(position: Int, imageView: ImageView)
    }
}